/* This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package Vista;

//**********************************************************************
//Import list
//**********************************************************************
import Controlador.Informe.GestorInformes;
import Controlador.Informe.GestorInformesPDF;
import java.io.File;
import java.net.URL;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import Controlador.*;
import Modelo.Accion;
import Modelo.Plugin;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.*;
import javax.swing.filechooser.*;
import javax.swing.text.JTextComponent;

import Vista.JWizard.*;
import Vista.*;
import org.jdesktop.swingworker.SwingWorker;

/**
 * This class simulates an installation Wizard using the FLib JWizard component.
 * <hr>
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the Artistic License. You should have received a copy of the
 * Artistic License along with this program. If not, a copy is available at <a
 * href="http://opensource.org/licenses/artistic-license.php">
 * opensource.org</a>.
 * 
 * @author Antonio Freixas
 *
 */
// Copyright � 2004 Antonio Freixas
// All Rights Reserved.
class Aplicacion extends JWizardDialog {

    // **********************************************************************
    // Public Constants
    // **********************************************************************
    GestorPlugins prueba1 = new GestorPlugins();
    Vector plugins = new Vector();
    int nivel_gravedad;
    Analizador analizador = new Analizador();
    String PDFSalida;

    // **********************************************************************
    // main
    // **********************************************************************
    public static void main(String[] args) {
        new Aplicacion();
        System.exit(0);
    }

    // **********************************************************************
    // Constructors
    // **********************************************************************
    /**
     * Create an instance of Example1. Note that this class is a subclass of
     * JWizardDialog.
     */
    public Aplicacion() {


        // We want the dialog modal -- when the dialog is finished, we
        // exit the program

        setModal(true);

        // Set the dialog title. This is the title for the wizard as a
        // whole

        setTitle("AFA (Aplicacion de analisis Forense)");

        // Set the logo image

        //URL url = getClass().getResource("C:\\Documents and Settings\\admin\\My Documents\\NetBeansProjects\\AFA\\Logo.gif");

        setWizardIcon(new ImageIcon(Constantes.getImagesDir() + "banner.GIF"));

        //        setIconImage(new ImageIcon("Logo.gif").getImage());
//                setIconImage(new Image("Logo.gif"));

        Image img = Toolkit.getDefaultToolkit().getImage(Constantes.getImagesDir() + "Logo.gif");

        //setIconImage(img);


        // Create each step

        addWizardPanel(new Step0());
        addWizardPanel(new Step1());
        addWizardPanel(new Step2());
        addWizardPanel(new Step4());

        // We don't want to have the cancel button enabled when we're done

        disableCancelAtEnd();

        // Make the dialog visible

        addHelpButton();
        pack();

        setVisible(true);
    }

    // **********************************************************************
    // Protected
    // **********************************************************************
    /**
     * If the user presses cancel, we want to give him/her the option of
     * continuing with the installation.
     */
    protected void cancel() {
        int response = JOptionPane.showConfirmDialog(this,
                "Cancelar la Ejecucion de AFA?", "Cancelar la ejecucion",
                JOptionPane.OK_CANCEL_OPTION);

        if (response == JOptionPane.OK_OPTION) {
            super.cancel();
        }
    }

    // **********************************************************************
    // Inner Classes
    // **********************************************************************
    // **********************************************************************
    // Step0
    // **********************************************************************
    // This panel just introduces the Example1 wizard (which pretends that
    // its going to install a package called Example1)
    private class Step0 extends JWizardPanel {

        private JTextField field;
        private JTextField f1;

        public Step0() {

            //Tools.obtenerUnidadesLinux();

           
            

            setStepTitle(Idioma.getText("Datos del analista forense"));

            JPanel contentPane = getContentPane();
            contentPane.setLayout(new GridBagLayout());

            // Field to enter install location

            JPanel nombre = new JPanel();
            nombre.setLayout(new FlowLayout());
            JLabel label = new JLabel();
            label.setText(Idioma.getText("Introduzca su nombre"));
            f1 = new JTextField(15);
            GridBagConstraints constraints = new GridBagConstraints();

            constraints.weighty = 1.0; // La fila 0 debe estirarse, le ponemos
            // un 1.0
            constraints.gridwidth = 1; // El boton de texto ocupa dos columnas.
            constraints.gridheight = 1; // El boton de texto ocupa 2 filas.



            nombre.add(label);

            nombre.add(f1);

            constraints.gridx = 0; // El �rea de boton empieza en la columna
            // cero.
            constraints.gridy = 0; // El �rea de boton empieza en la fila cero
            contentPane.add(nombre, constraints);


            JPanel certificado = new JPanel();
            certificado.setLayout(new FlowLayout());



            JLabel label2 = new JLabel();
            label2.setText(Idioma.getText("Fichero de certificado:"));

            field = new JTextField(15);

            // Browse button for browsing to install location

            final JButton browse = new JButton("Browse");
            browse.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    File defaultDir = new File("");
                    JFileChooser chooser = new JFileChooser(defaultDir);
                    JFileChooser jf = new JFileChooser();
                    FileNameExtensionFilter filter1 = new FileNameExtensionFilter(
                            "PSCK12 File", "p12");
                    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                    chooser.setFileFilter(filter1);
                    int result = chooser.showDialog(browse, "Select");
                    if (result == JFileChooser.APPROVE_OPTION) {
                        field.setText(chooser.getSelectedFile().getAbsolutePath());
                    }
                }
            });
            constraints = new GridBagConstraints();
            constraints.gridx = 0; // El �rea de boton empieza en la columna
            // cero.
            constraints.gridy = 1; // El �rea de boton empieza en la fila cero
            constraints.weighty = 1.0; // La fila 0 debe estirarse, le ponemos
            // un 1.0
            constraints.gridwidth = 1; // El boton de texto ocupa dos columnas.
            constraints.gridheight = 1; // El boton de texto ocupa 2 filas.
            constraints.insets = new Insets(5, 0, 5, 0);
            certificado.add(label2);
            certificado.add(field);
            certificado.add(browse);

            contentPane.add(certificado, constraints);


            //field.setSize(50, 50);


            // Set the previous and next steps

            setNextStep(1);
        }

        // We're going to override the next button so we can check if the
        // specified directory exists. If it does, we go on to the next step.
        // If not, we ask whether we should create it. If the answer is No or
        // if we can't create it, we remain on the current step
        protected void next() {
            String folderName = field.getText().trim();
            // If it exists, check that it is a folder and not a file

            // If nothing was entered, report an error

            if (folderName.length() < 1) {
                JOptionPane.showMessageDialog(
                        Step0.this,
                        Idioma.getText("No se ha elegido un fichero para firmar, no se podran firmar los informes"),
                        folderName, JOptionPane.PLAIN_MESSAGE);
            } else {
                analizador.setP12File(folderName);
                analizador.setClaveP12(JOptionPane.showInputDialog(getContentPane(), Idioma.getText("Introduzca su clave para firmar:"),JOptionPane.QUESTION_MESSAGE)); // el icono sera un
                // iterrogante);

                //analizador.setClaveP12(pass.getText());
            }

            // If it doesn't exist, query whether we should create it

            if (f1.getText().length() > 0) {
                analizador.setAnalizador(f1.getText());
                super.next();
                return;
            } else {
                JOptionPane.showMessageDialog(Step0.this,
                        "Es necesario introducir un nombre de Analista",
                        folderName, JOptionPane.PLAIN_MESSAGE);
                return;
            }

        }
    }

    // **********************************************************************
    // Step1
    // **********************************************************************
    // This panel displays the installation license
    private class Step1 extends JWizardPanel {

        Vector unidades;
        JCheckBox[] Unidad;
        String temporal;

        public Step1() {
            unidades = new Vector();
            setStepTitle(Idioma.getText("Seleccion de la unidad"));

            GridBagLayout thisLayout = new GridBagLayout();
            JPanel pane = new JPanel();
            pane.setLayout(thisLayout);
            JLabel texto = new JLabel();

            texto.setText(Idioma.getText("Seleccione las unidades sobre las que quiere realizar el analisis:"));
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.gridx = 1; // El �rea de boton empieza en la columna
            // cero.
            constraints.gridy = 0; // El �rea de boton empieza en la fila cero
            constraints.weighty = 1.0; // La fila 0 debe estirarse, le ponemos
            // un 1.0
            constraints.gridwidth = 1; // El boton de texto ocupa dos columnas.
            constraints.gridheight = 1; // El boton de texto ocupa 2 filas.
            pane.add(texto, constraints);

            String raices[];
            if (System.getProperties().getProperty("os.name").startsWith("Windows") || System.getProperties().getProperty("os.name").startsWith("Microsoft")) {
                raices = Tools.obtenerUnidadesWindows();
            } else {
                raices = Tools.obtenerUnidadesLinux();
            }
            Unidad = new JCheckBox[raices.length];

            for (int i = 0; i < raices.length; i++) {
                if (raices[i] != null) {                
                    constraints = new GridBagConstraints();
                    constraints.gridx = 1; // El �rea de boton empieza en la columna
                    // cero.
                    constraints.gridy = 2 + i; // El �rea de boton empieza en la
                    // fila cero
                    constraints.weighty = 1.0; // La fila 0 debe estirarse, le
                    // ponemos un 1.0
                    constraints.gridwidth = 1; // El boton de texto ocupa dos
                    // columnas.
                    constraints.gridheight = 1; // El boton de texto ocupa 2 filas.

                    Unidad[i] = new JCheckBox(raices[i].toString());
                    Unidad[i].setName(raices[i]);
                    temporal = raices[i];
                    Unidad[i].setSelected(false);
                    pane.add(Unidad[i], constraints);
                    Unidad[i].setText(raices[i]);
                    Unidad[i].addItemListener(new ItemListener() {

                        public void itemStateChanged(ItemEvent e) {
                            //Comprobamos todos los checkbox y si alguno
                            int jc = 0;
                            boolean enc = false;
                            for (jc = 0; jc < Unidad.length; jc++) {
                                if (Unidad[jc].isSelected()) {
                                    enc = true;
                                }
                            }
                            if (enc) {
                                setNextStep(2);
                            } else {
                                setNextStep(-1);
                            }

                        }
                    });
                }
                ;
            }

            getContentPane().add(pane);

            new ItemListener() {

                public void itemStateChanged(ItemEvent e) {
                    if (e.getStateChange() == ItemEvent.SELECTED) {

                        setNextStep(2);
                    } else {
                        setNextStep(-1);
                    }
                }
            };

            // Set the previous and next steps. Note that we don't have a next
            // step until the user agrees to the license terms

            setBackStep(-1);
            setNextStep(-1);
        }

        protected void next() {
            Vector unid = new Vector();
            for (int i = 0; i < Unidad.length; i++) {
                if (Unidad[i].isSelected()) {
                    unid.add(Unidad[i].getName());
                }
            }

            analizador.setUnidades(unid);
            super.next();
            return;
        }
    }

    // **********************************************************************
    // Step2
    // **********************************************************************
    // Select the installation location
    private class Step2 extends JWizardPanel {

        private JTextField field;
        JCheckBox[] Plugin;
        Vector seleccionados = new Vector();
        Plugin p;

        public Step2() {


            setStepTitle(Idioma.getText("Seleccion de los plugins"));
            JPanel panel_principal = new JPanel();
            panel_principal.setLayout(new FlowLayout());
            JPanel pane = new JPanel();
            pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));

            JScrollPane scroll = new JScrollPane(pane);
            scroll.setPreferredSize(new Dimension(300, 320));


            scroll.setVerticalScrollBarPolicy(scroll.VERTICAL_SCROLLBAR_ALWAYS);




            JLabel texto = new JLabel();

            GestorPlugins GP = new GestorPlugins();
            plugins = GP.ListarPlugins();
            Iterator i = plugins.iterator();

            Plugin = new JCheckBox[plugins.size()];
            int contador = 0;
            while (i.hasNext()) {

                p = (Plugin) i.next();
                Plugin[contador] = new JCheckBox(p.get_name());
                Plugin[contador].setName(p.get_name());
                Plugin[contador].setSelected(false);
                pane.add(Plugin[contador]);
                Plugin[contador].setText(p.get_name() + p.get_version());
                Plugin[contador].addItemListener(new ItemListener() {

                    public void itemStateChanged(ItemEvent e) {
                        int jc = 0;
                        boolean enc = false;
                        for (jc = 0; jc < Plugin.length; jc++) {
                            if (Plugin[jc].isSelected()) {
                                enc = true;
                            }
                        }
                        if (enc) {
                            setNextStep(3);
                        } else {
                            setNextStep(-1);
                        }
                    }
                });
                contador++;
            }

            //Codigo de seleccionar todo
            JButton sel_todo = new JButton();
            sel_todo.setText(Idioma.getText("Seleccionar todo"));
            sel_todo.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                      int jc = 0;
                        boolean enc = false;
                        for (jc = 0; jc < Plugin.length; jc++) {
                            Plugin[jc].setSelected(true);
                            }
                        }
                });


            pack();
            panel_principal.add(scroll);
            panel_principal.add(sel_todo);
            getContentPane().add(panel_principal);

            new ItemListener() {

                public void itemStateChanged(ItemEvent e) {
                    if (e.getStateChange() == ItemEvent.SELECTED) {
                        setNextStep(3);
                    } else {
                        setNextStep(-1);
                    }
                }
            };

            // Set the previous and next steps. Note that we don't have a next
            // step until the user agrees to the license terms

            // Set the previous and next steps

            setBackStep(-1);
            setNextStep(3);
        }

        // We're going to override the next button so we can check if the
        // specified directory exists. If it does, we go on to the next step.
        // If not, we ask whether we should create it. If the answer is No or
        // if we can't create it, we remain on the current step
        protected void next() {
            for (int l = 0; l < Plugin.length; l++) {
                Iterator i = plugins.iterator();
                while (i.hasNext()) {
                    Plugin plug = (Plugin) i.next();
                    if (Plugin[l].getText().compareTo(
                            plug.get_name() + plug.get_version()) == 0) {
                        if (Plugin[l].isSelected()) {
                            seleccionados.add(plug);
                        }
                    }
                }
            }
            analizador.setPlugins(seleccionados);
            super.next();
            return;
        }
    }

    private class Step4 extends JWizardPanel {

        JComboBox combo;

        public Step4() {

            setStepTitle(Idioma.getText("Profundidad de analisis"));

            getContentPane().setLayout(new GridBagLayout());
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.gridx = 0; // El �rea de boton empieza en la columna
            // cero.
            constraints.gridy = 0; // El �rea de boton empieza en la fila cero

            JLabel jl = new JLabel();
            jl.setText(Idioma.getText("A mayor profundidad mayor tiempo empleado"));
            getContentPane().add(jl, constraints);

            constraints.gridx = 0; // El �rea de boton empieza en la columna
            // cero.
            constraints.gridy = 1; // El �rea de boton empieza en la fila cero

            JLabel j2 = new JLabel();
            j2.setText("					");
            getContentPane().add(j2, constraints);

            combo = new JComboBox();
            combo.addItem(Idioma.getText("Bajo"));
            combo.addItem(Idioma.getText("Medio"));
            combo.addItem(Idioma.getText("Alto"));
            constraints.gridx = 0; // El �rea de boton empieza en la columna
            // cero.
            constraints.gridy = 2; // El �rea de boton empieza en la fila cero
            getContentPane().add(combo, constraints);

            // Accion a realizar cuando el JComboBox cambia de item
            // seleccionado.
            setBackStep(-1);
            setNextStep(3);
        }

        // We override the next() method just to determine what the user
        // selected
        protected void next() {
            if (combo.getSelectedItem().toString().compareTo(Idioma.getText("Bajo")) == 0) {
                nivel_gravedad = 1;
            }
            if (combo.getSelectedItem().toString().compareTo(Idioma.getText("Medio")) == 0) {
                nivel_gravedad = 2;
            }
            if (combo.getSelectedItem().toString().compareTo(Idioma.getText("Alto")) == 0) {
                nivel_gravedad = 3;
            }

            addWizardPanel(new Step8());
            setBackStep(-1);
            setNextStep(4);
            super.next();
        }
    }

    private class Step8 extends JWizardPanel {

        JProgressBar progressBar;
        public JLabel progreso = new JLabel();
        public JLabel estado = new JLabel();

        public Step8() {

            setStepTitle(Idioma.getText("Espere por favor,realizando las operaciones solicitadas"));

            setLayout(new GridBagLayout());
            progressBar = new JProgressBar();
            progressBar.setIndeterminate(true);
            progreso.setText("Analizando: ");
            estado.setText("Realizando:");
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.gridx = 0; // El �rea de boton empieza en la columna
            // cero.
            constraints.gridy = 1; // El �rea de boton empieza en la fila cero
            constraints.weighty = 1.0; // La fila 0 debe estirarse, le ponemos
            // un 1.0
            constraints.gridwidth = 1; // El boton de texto ocupa dos columnas.
            constraints.gridheight = 1; // El boton de texto ocupa 2 filas.

            add(progreso, constraints);
            constraints.gridx = 0; // El �rea de boton empieza en la columna
            // cero.
            constraints.gridy = 2; // El �rea de boton empieza en la fila cero
            constraints.weighty = 1.0; // La fila 0 debe estirarse, le ponemos
            // un 1.0
            constraints.gridwidth = 1; // El boton de texto ocupa dos columnas.
            constraints.gridheight = 1; // El boton de texto ocupa 2 filas.
            add(progressBar, constraints);
            constraints.gridx = 0; // El �rea de boton empieza en la columna
            // cero.
            constraints.gridy = 3; // El �rea de boton empieza en la fila cero
            constraints.weighty = 1.0; // La fila 0 debe estirarse, le ponemos
            // un 1.0
            constraints.gridwidth = 1; // El boton de texto ocupa dos columnas.
            constraints.gridheight = 1; // El boton de texto ocupa 2 filas.
            add(estado, constraints);

            analizador.setNivel_gravedad(nivel_gravedad);
            analizador.categorizar();

            MiWorker trabajador = new MiWorker();
            trabajador.addPropertyChangeListener(new PropertyChangeListener() {

                public void propertyChange(PropertyChangeEvent evt) {
                    if ("progress".equals(evt.getPropertyName())) {
                    }
                }
            });

            trabajador.execute();

            setBackStep(-1);
            setNextStep(-1);
        }

        public void setProgressText(String texto) {
            progreso.setText(texto);
        }

        public void setStatusText(String texto) {
            estado.setText(texto);
        }

        // Accion a realizar cuando el JComboBox cambia de item seleccionado.
        // We override the next() method just to determine what the user
        // selected
        protected void next() {

            // analizador.ejecutar(nivel_gravedad);

            // analizador.ejecutar(nivel_gravedad);

            // addWizardPanel(new Step5());

            setBackStep(-1);
            setNextStep(5);
            super.next();
        }

        class MiWorker extends SwingWorker<String, Void> {

            @Override
            protected String doInBackground() throws Exception {
                analizador.ejecutarVisual(nivel_gravedad, progreso, estado);
                return "Operacion finalizada";
            }

            @Override
            public void done() {
                try {
                    addWizardPanel(new Step5());
                    setBackStep(-1);
                    setNextStep(4);
                    next();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    // **********************************************************************
    // Step5
    // **********************************************************************
    private class Step5 extends JWizardPanel {

        private JTextField field;
        private JTextField f1;
        private Vector acc = new Vector();
        private Vector acc_jcheck = new Vector();

        public Step5() {
            int posicion = 1;

            setStepTitle(Idioma.getText("Programas detectados:"));

            JPanel panel1 = new JPanel();
            panel1.setLayout(new GridBagLayout());
            JPanel panel0 = new JPanel();

            // Field to enter install location

            JLabel label = new JLabel();
            label.setText("<html>" + Idioma.getText("Selecciona las acciones que desea ejecutar <br> de los siguientes programas encontrados") + "</html>");
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.gridx = 0; // El �rea de boton empieza en la columna
            // cero.
            constraints.gridy = 0; // El �rea de boton empieza en la fila cero
            panel0.add(label, constraints);

            
            super.add(panel0, BorderLayout.NORTH);
            JScrollPane scroll = new JScrollPane(panel1);
            scroll.setPreferredSize(new Dimension(260, 320));
            super.add(scroll, BorderLayout.CENTER);
            Iterator i = analizador.getPlugins().iterator();
            while (i.hasNext()) {
                Plugin p = (Plugin) i.next();
                if (p.encontrado()) {
                    JLabel jl = new JLabel();
                    jl.setName(p.get_name() + p.get_version());
                    jl.setText(p.get_name() + p.get_version());
                    constraints.gridx = 0; // El �rea de boton empieza en la
                    // columna cero.
                    constraints.gridy = posicion; // El �rea de boton empieza en
                    // la fila cero
                    constraints.insets = new Insets(5, 0, 5, 0);
                    panel1.add(jl, constraints);

                    constraints.gridx = 1; // El �rea de boton empieza en la
                    // columna cero.
                    constraints.gridy = posicion; // El �rea de boton empieza en
                    // la fila cero
                    constraints.insets = new Insets(5, 0, 5, 0);

                    constraints.gridx = 2; // El �rea de boton empieza en la
                    // columna cero.
                    constraints.gridy = posicion; // El �rea de boton empieza en
                    // la fila cero
                    constraints.insets = new Insets(5, 0, 5, 0);

                    panel1.add(crearPanelAcciones(p), constraints);
                    posicion++;
                }

            }
            //

            setNextStep(4);
            setBackStep(-1);
        }

        public JPanel crearPanelAcciones(Plugin plug) {
            JPanel acciones = new JPanel();
            acciones.setLayout(new BoxLayout(acciones, BoxLayout.Y_AXIS));

            acciones.setName(plug.get_name() + plug.get_version());
            GridBagConstraints constraints = new GridBagConstraints();
            Iterator i = plug.get_acciones().iterator();
            while (i.hasNext()) {
                Accion ac = (Accion) i.next();
                acc.add(ac);
                JCheckBox jcheck = new JCheckBox();
                jcheck.setText(ac._explicacionAccion);
                acc_jcheck.add(jcheck);
                jcheck.setAlignmentX(Component.LEFT_ALIGNMENT);
                acciones.add(jcheck);
                acciones.setBorder(BorderFactory.createTitledBorder(""));
            }
            return acciones;

        }

        // We're going to override the next button so we can check if the
        // specified directory exists. If it does, we go on to the next step.
        // If not, we ask whether we should create it. If the answer is No or
        // if we can't create it, we remain on the current step
        protected void next() {
            for (int i = 0; i < acc.size(); i++) {
                JCheckBox j = (JCheckBox) acc_jcheck.get(i);
                Accion a = (Accion) acc.get(i);
                if (j.isSelected()) {
                    analizador.getAccionador().addAccion(a);
                }

            }
            analizador.getAccionador().categorizar();
            analizador.getAccionador().ejecutar();
            addWizardPanel(new Step6());
            setNextStep(6);
            setBackStep(-1);
            super.next();
        }
    }

    private class Step6 extends JWizardPanel {

        JTextField field;
        JCheckBox jcheck;

        public Step6() {
            setStepTitle(Idioma.getText("Generacion del informe:"));
            GridBagConstraints constraints = new GridBagConstraints();
            JLabel n = new JLabel("Seleccione el destino del informe en formato PDF:");
            n.setText(Idioma.getText("Seleccione el destino del informe en formato PDF:"));

            getContentPane().setLayout(new GridBagLayout());
            constraints.gridx = 0;
            constraints.gridy = 0;
            constraints.insets = new Insets(25, 5, 25, 5);
            getContentPane().add(n, constraints);

            JPanel archivo = new JPanel();
            JLabel label2 = new JLabel();
            label2.setText(Idioma.getText("Fichero de salida:"));

            archivo.setLayout(new GridBagLayout());
            constraints.gridx = 0;
            constraints.gridy = 0;
            archivo.add(label2, constraints);
            field = new JTextField(15);
            constraints.gridx = 2;
            constraints.gridy = 0;
            archivo.add(field, constraints);

            // Browse button for browsing to install location

            final JButton browse = new JButton("Browse");
            browse.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    File defaultDir = new File("");
                    JFileChooser chooser = new JFileChooser(defaultDir);
                    JFileChooser jf = new JFileChooser();
                    FileNameExtensionFilter filter1 = new FileNameExtensionFilter("PDF Files", "PDF");
                    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                    chooser.setFileFilter(filter1);
                    int result = chooser.showDialog(browse, "Select");
                    if (result == JFileChooser.APPROVE_OPTION) {
                        field.setText(chooser.getSelectedFile().getAbsolutePath());
                    }
                }
            });
            constraints.gridx = 3;
            constraints.gridy = 0;
            archivo.add(browse, constraints);

            jcheck = new JCheckBox("Firmar");
            jcheck.setText(Idioma.getText("Firmar"));
            getContentPane().add(jcheck, constraints);

            constraints.gridx = 3;
            constraints.gridy = 2;
            constraints.insets = new Insets(0, 0, 0, 0);

            archivo.add(jcheck, constraints);
            jcheck.setEnabled(false);
            constraints.gridx = 0;
            constraints.gridy = 1;
            getContentPane().add(archivo, constraints);

            constraints.gridx = 3;
            constraints.gridy = 2;

            if (analizador.getP12File() != null) {
                if (analizador.getP12File().length() > 0) {
                    jcheck.setEnabled(true);
                }
            }
            setNextStep(6);
            setBackStep(-1);

        }

        protected void next() {
            GestorInformes g = new GestorInformes();
            java.util.Date fechaActual = new java.util.Date(); //Fecha actual del sistema
            g.escribirInformeXML(Constantes.getDirectorio_informes() + File.separator + "inf_" + fechaActual.getDate() + fechaActual.getTime() + ".xml", plugins);
            GestorInformesPDF gr = new GestorInformesPDF();
            PDFSalida = field.getText();

            if (jcheck.isSelected()) {
                gr.escribirInformePDF(field.getText() + "" + 1, analizador);
                boolean result_firmar = gr.firmarInforme(field.getText() + "" + 1, field.getText(), analizador.getP12File(),
                        analizador.getClaveP12());
                File antiguo = new File(field.getText() + "" + 1);
                antiguo.delete();
            } else {
                gr.escribirInformePDF(field.getText(), analizador);
            }
            addWizardPanel(new Step9());
            setNextStep(7);
            setBackStep(-1);
            super.next();
        }

        private class Step9 extends JWizardPanel {

            public Step9() {
                JLabel j = new JLabel(
                        "<html> <center>Su informe en PDF esta en el fichero de salida <br> <br> <br>" + PDFSalida + "</center></html>");
                getContentPane().add(j);


            }

            private void finish() {
            }
        }
    }

    public void finish() {
        System.exit(0);

    }
}
